package com.example.interceptmybatis.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName PhoneValidator
 * @Description TODO
 * @Author 郭敖
 * @Date 2024年09月05日 22:00
 * @Version 1.0
 */
@Slf4j
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    @Override
    public void initialize(Phone phone) {
        String message = phone.message();
        log.info("message:{}", message);
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        String REGEX_PHONE = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
        return s.matches(REGEX_PHONE);
    }
}
